import request from "@/utils/request.js";

//设置这次请求的数据格式
const headers = {
  "Content-type": "application/x-www-form-urlencoded",
};

//请求头添加 Authorization:Basic client_id:client_secret
const auth = {
  username: "pg-blog-admin",
  password: "123456",
};

export default {
  login(data) {
    return request({
      headers,
      auth,
      url: `/auth/login`,
      method: "post",
      params: data,
    });
  },
  //查询有没有用户名
  getUserByUsername(username) {
    return request({
      url: `/system/api/user/username/${username}`,
      method: "get",
    });
  },
  //注册
  register(data) {
    return request({
      headers,
      auth,
      url: `/system/api/user/register`,
      method: "post",
      data,
    });
  },
  //编写用户协议的接口  html文件在public文件夹中
  getProtocol() {
    return request({
      url: `${window.location.href}/xieyi.html`,
      method: "get",
    });
  },

  //退出系统
  logout(accessToken) {
    return request({
      url: `/auth/logout`,
      method: "get",
      params: {
        accessToken,
      },
    });
  },
  refreshToken(refreshToken) {
    return request({
      url: "/auth/user/refreshToken",
      method: "get",
      params: {
        refreshToken,
      },
    });
  },
};
